package com.tfleo.mealssenger.adapter;

import java.util.List;

import com.github.ignition.core.widgets.RemoteImageView;
import com.tfleo.mealssenger.FoodActivity;
import com.tfleo.mealssenger.PlaceActivity;
import com.tfleo.mealssenger.R;
import com.tfleo.mealssenger.object.Food;
import com.tfleo.mealssenger.object.Notice;

import android.content.Context;
import android.content.Intent;
import android.graphics.drawable.Drawable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Gallery;
import android.widget.TextView;


/**
 * Can be used as an adapter for an Android {@link Gallery} view. This adapter loads the images to
 * be shown from the web.
 * 
 * @author Matthias Kaeppler
 */
public class NoticeGalleryAdapter extends BaseAdapter {
    private List<Notice> mObjects;
    private Context mContext;
    private LayoutInflater mInflater;

    public NoticeGalleryAdapter(Context context) {
        mContext = context;
    }

    /**
     * @param context
     *            the current context
     * @param imageUrls
     *            the set of image URLs which are to be loaded and displayed
     */
    public NoticeGalleryAdapter(Context context, List<Notice> objects, LayoutInflater inflater) {
        mInflater = inflater;
    	mContext = context;
    	mObjects = objects;
    }

    @Override
    public int getCount() {
        return mObjects.size();
    }

    @Override
    public Object getItem(int position) {
        return mObjects.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        final Notice notice = (Notice) getItem(position);
        ViewHolder holder = null;
        TextView noteView = null;

        if (convertView == null) {
        	convertView = mInflater.inflate(R.layout.notice_entry, null);
			holder = new ViewHolder(convertView);
			convertView.setTag(holder);
        }
        
        holder = (ViewHolder) convertView.getTag();
        noteView = holder.getNotifView();  
        noteView.setText(notice.message);
        
        onGetView(position, convertView, parent);

        return convertView;
    }

    protected void onGetView(int position, View convertView, ViewGroup parent) {
        // for extension
    }

    private class ViewHolder {
		private View vRow;
		private TextView vNotif = null;

		public ViewHolder(View row) {
			vRow = row;
		}

		public TextView getNotifView() {
			if (vNotif == null) {
				vNotif = (TextView) vRow.findViewById(R.id.note);
			}
			return vNotif;
		}
	}
}
